import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Location } from '@angular/common';

import { Article } from '../Article';
import { HeroService } from '../hero.service';
import {PageInfo} from '../PageInfo';
import {UserService} from '../user.service';
@Component({
  selector: 'app-articles',
  templateUrl: './articles.component.html',
  styleUrls: ['./articles.component.css']
})
export class ArticlesComponent implements OnInit {
  constructor(private route: ActivatedRoute, private heroService: HeroService, private location: Location, private userService: UserService) {
  }
  articles: Article[] = [];
  pageInfo: PageInfo<Article>;
  i = 0;
  isLogin: boolean;
  user: any;
  ngOnInit() {
    this.getHeroes();
    this.isLogin = this.userService.isLogin();
    console.log(this.isLogin );
  }
  numberIChange(i: number) {
    this.heroService.getHeroes(i)
      .subscribe(heroes => {
        this.articles = heroes.data.list;
        this.pageInfo = heroes.data;
      });
  }
  getHeroes(): void {
    this.heroService.getHeroes(1)
      .subscribe(resp => {
        if (resp.data) {
          this.articles = resp.data.list;
          this.pageInfo = resp.data;
        }
      });
  }
}
